package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.TreeProblem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 中序遍历树
 *
 * @author tzp
 * @since 2020/10/12
 */
public class LC94 implements TreeProblem {
    public List<Integer> inorderTraversal(TreeNode root) {
        if (root == null) return Collections.emptyList();
        List<Integer> result = new ArrayList<>();
        dfsMid0(root, result);
        return result;
    }

    //深度-中序-递归, inorderLC
    public static void dfsMid0(TreeNode node, List<Integer> result) {
        if (node.left != null) {
            dfsMid0(node.left, result);
        }
        result.add(node.val);
        if (node.right != null) {
            dfsMid0(node.right, result);
        }
    }

    public static void main(String[] args) {
        Integer[] a = {1, 2, 4, 3, 5, 7, 10, 6, null, 8, null, 11, 9, 15, null, null, null, 12, null, null, null, 13, null, null, null, null, 14};
        TreeNode treeNode = TreeNode.arrayToTreeNode(a);
        System.out.println(new LC94().inorderTraversal(treeNode));
    }
}
